package com.zh.ChinaZipSearch;


import org.apache.axis.message.MessageElement;
import org.junit.Test;

import javax.xml.rpc.ServiceException;
import java.rmi.RemoteException;
import java.util.ArrayList;

public class testZipSearch {

    public static String[] testZipSearch() {
        ChinaZipSearchWebServiceLocator serviceLocator = new ChinaZipSearchWebServiceLocator();
        ChinaZipSearchWebServiceSoap_PortType portType = null;
        try {
            portType = serviceLocator.getChinaZipSearchWebServiceSoap();
        } catch (ServiceException e) {
            e.printStackTrace();
        }
//            GetZipCodeByAddressResponseGetZipCodeByAddressResult result = portType.getZipCodeByAddress("广东省", "深圳市", "民行路口", null);
        String[] result = new String[0];
        try {
            result = portType.getSupportCity("广东");
        } catch (RemoteException e) {
            e.printStackTrace();
        }
        return result;
    }


    public static void main(String[] args) {
        String[] strings = testZipSearch();
        for (int i = 0; i < strings.length; i++) {
//            System.out.print(strings[i].substring(strings[i].length()-1));
//            System.out.print(strings[i].indexOf("县"));
            if (strings[i].indexOf("县") > 0) {
                System.out.print(strings[i]);
            }
        }
    }

    @Test
    public void getByaddress() {
        ChinaZipSearchWebServiceLocator locator = new ChinaZipSearchWebServiceLocator();
        try {
            ChinaZipSearchWebServiceSoap_PortType portType = locator.getChinaZipSearchWebServiceSoap();
            GetZipCodeByAddressResponseGetZipCodeByAddressResult result = portType.getZipCodeByAddress("广东", "深圳", "龙华新区", "");
            MessageElement[] element = result.get_any();
//            ArrayList list = element[1].namespaces;
//            for (int i = 1; i < list.size(); i++) {
//                list.get(i);
//            }
//            for (int i = 0; i < element.length; i++) {
//                System.out.println(element[i]);
//            }
            String strings = element[1].toString();
            System.out.println(strings);
        } catch (ServiceException e) {
            e.printStackTrace();
        } catch (RemoteException e) {
            e.printStackTrace();
        }

    }
}


